package cn.es;

import java.util.concurrent.TimeUnit;

public class T3 {
    StringBuffer su = new StringBuffer();

    Object lock = new Object();

    void m() {
        synchronized (lock) {
            for (int i = 0; i < 1000; i++) {
                su.append("a");
            }
        }
    }

    public static void main(String[] args) {
        long ss = System.currentTimeMillis();
        T3 t = new T3();
        new Thread(t::m).start();
        new Thread(t::m).start();
        new Thread(t::m).start();
        new Thread(t::m).start();
        new Thread(t::m).start();

        try {
            TimeUnit.SECONDS.sleep(5);
            System.out.println(t.su.length());
            long ee = System.currentTimeMillis();
            System.out.println(ee - ss - 5000);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
